package com.jingyanzi.sys.client.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jingyanzi.sys.domain.DictionariesDO;
import com.jingyanzi.sys.domain.RegionDO;
import com.jingyanzi.sys.domain.result.ResultDO;
import com.jingyanzi.sys.domain.result.ResultSupport;
import com.jingyanzi.sys.domain.service.ISettingService;
import com.jingyanzi.sys.util.CityJsonUtil;

@RestController
@RequestMapping("/api")
public class DicClientImpl  {

	@Autowired
	private ISettingService settingService;
	
	@Autowired
	private CityJsonUtil cityJsonUtil;

	
	@RequestMapping("/dic/{id}")
	public DictionariesDO get(@PathVariable(value = "id") Integer id) {
		ResultDO res = settingService.getDictionariesById(id);
		DictionariesDO domain = (DictionariesDO) res.getModel(ResultSupport.FIRST_MODEL_KEY);
		return domain;
	}

	
	@RequestMapping("/region/{province}/{city}/{district}")
	public RegionDO getRegionDO(@PathVariable(value = "province") String province,
			@PathVariable(value = "city") String city, @PathVariable(value = "district") String district) {
		RegionDO regionDO = cityJsonUtil.getRegionDO(province, city, district);
		return regionDO;
	}

	
	@RequestMapping("/regionCode/{province}/{city}/{district}")
	public RegionDO getRegionCode(@PathVariable(value = "province") String province,
			@PathVariable(value = "city") String city, @PathVariable(value = "district") String district) {
		RegionDO regionDO = cityJsonUtil.getRegionCode(province, city, district);
		return regionDO;
	}

}